package com.example.tests;

import java.io.File;
import java.util.Date;
import java.util.Random;

public abstract class DataGeneratorBase {
	
	public static final int CSV_TYPE = 0;
	public static final int XML_TYPE = 1;

	public static boolean checkArguments(String[] args){
		if (args.length < 3) {
			System.out
					.println("Please specify parameters: <amount of test data> <file> <format>");
			return false;
		}
		
		if (new File(args[1]).exists()){
			System.out.println("File exists, please remove it manually: "+args[1]);
			return false;
		}

		if (!("csv".equals(args[2])|("xml".equals(args[2])))) {
			return false;
		} 
		return true;
	}

	private static String generateRandomString() {
		// TODO: make relevant random string generator. not just prefix + random
		// integer.
		Random rnd = new Random();
		return "test " + rnd.nextInt();
	}

	protected static String generateRandomString(int emptyProb) {
		Random rnd = new Random();
		if (rnd.nextInt(100) <= emptyProb) {
			return "";
		} else {
			return generateRandomString();
		}
	}
	
	public static String generateRandomString(int emptyProb, int nullProb){
		Random rnd = new Random();
		if (rnd.nextInt(100) <= nullProb) {
			return null;
		} else {
			return generateRandomString(emptyProb);
		}
	}

	public static Date generateRandomDate() {
		Random rnd = new Random();
		return new Date(Math.abs(System.currentTimeMillis() - rnd.nextLong()));
	}
}
